<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>新建采购申请</legend>
        </fieldset>
        <form class="layui-form" id="purchasingapply">
            <table>
                <tr>
                    <td>
                        <div class="layui-form-item">
                            <label class="layui-form-label">采购主题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="rmtPDescription" lay-verify="required" placeholder="请输入"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="layui-form-item">
                            <label class="layui-form-label">采购类别</label>
                            <div class="layui-input-inline">
                                <select name="rmtPType" lay-filter="aihao">
                                    <option value="设备采购">设备采购</option>
                                    <option value="物料采购">物料采购</option>
                                    <option value="杂物采购">杂物采购</option>
                                </select>
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="layui-form-item">
                            <label class="layui-form-label">到货地址</label>
                            <div class="layui-input-inline">
                                <input type="text" name="rmtPAddress" lay-verify="required" placeholder="请输入"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请人姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="rmtPName" lay-verify="required" placeholder="请输入"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请部门</label>
                            <div class="layui-input-inline">
                                <input type="text" name="rmtPDepartment" lay-verify="required" placeholder="请输入"
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="layui-inline">
                            <label class="layui-form-label">申请日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="rmtPDate" id="applydate" lay-verify="date"
                                       placeholder="yyyy-MM-dd"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>采购申请明细</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">物品名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="rmtPaiName" lay-verify="required" placeholder="请输入"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">物品单位</label>
                <div class="layui-input-inline">
                    <input type="text" name="rmtPaiType" lay-verify="required" placeholder="请输入"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">需求数量</label>
                <div class="layui-input-inline" style="width: 200px">
                    <table>
                        <tr>
                            <td>
                                <button type="button" class="layui-btn layui-btn-sm" id="deletenum"><i
                                        class="layui-icon">-</i>
                                </button>
                            </td>
                            <td><input type="text" id='needingnum' name="rmtPaiNum" lay-verify="required"
                                       value="0"
                                       autocomplete="off"
                                       class="layui-input"></td>
                            <td>
                                <button type="button" class="layui-btn layui-btn-sm" id="addnum"><i
                                        class="layui-icon">+</i>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">需求日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="rmtPaiDate" id="needingdate" lay-verify="date" placeholder="yyyy-MM-dd"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text" style="position: relative;top: 20px">
                <label class="layui-form-label">需求原因</label>
                <div class="layui-input-block">
                    <textarea name="rmtPaiReason" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item" style="position: relative;top: 20px">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="add">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'laydate', 'layer'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        laydate.render({
            elem: '#applydate',
            trigger: 'click',
        });
        laydate.render({
            elem: '#needingdate',
            trigger: 'click',
        });
        form.on('submit(add)', function (data) {
            $.post('/addPurchasingApply', $('#purchasingapply').serialize(), function (data) {
                if (data.code == 0) {
                    layer.msg("添加成功");
                    $("#purchasingapply")[0].reset();
                }
            })
            return false;
        })
        $("#addnum").click(function () {
            $("#needingnum").attr("value", function (n, v) {
                return parseInt(v) + 1;
            })
        })
        $("#deletenum").click(function () {
            if ($("#needingnum").val() > 0) {
                $("#needingnum").attr("value", function (n, v) {
                    return parseInt(v) - 1;
                })
            }
        })
    })
</script>
</body>
</html>